package com.example.a79273.shandianban.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.a79273.shandianban.R;
import com.example.a79273.shandianban.adapter.YouRenFragmentPagerAdapter;

import org.xutils.HttpManager;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * "有人"页面
 */
public class YouRen extends Fragment {

    private ViewPager topPages_vp, pages_vp;
    private TabLayout subtitles;
    private LinearLayout points_ll;
    private ImageView youLiao_iv;

    private HttpManager httpManager;

    private YouRenFragmentPagerAdapter mPagerAdapter;

    private List<YouRenPageFragment> pageFragments;
    private String[] titles;

    @Nullable
    @Override

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_youren, null);
        initView(view);
        initData();
        setData();
        setListener();
        return view;
    }

    private void setListener() {

    }

    private void setData() {
        pages_vp.setAdapter(mPagerAdapter);
        subtitles.setupWithViewPager(pages_vp);
    }

    private void initData() {
        httpManager = x.http();
        titles = getActivity().getResources().getStringArray(R.array.youRenPageTitles);
        pageFragments = new ArrayList<>();
        YouRenPageFragment pageFragment;
        Bundle bundle;
        for (int i = 0; i < titles.length; i++) {
            pageFragment = new YouRenPageFragment();
            bundle = new Bundle();
            bundle.putInt("location", i);
            pageFragment.setArguments(bundle);
            pageFragments.add(pageFragment);
        }

        mPagerAdapter = new YouRenFragmentPagerAdapter(getFragmentManager(), titles, pageFragments);

    }

    private void initView(View view) {
        topPages_vp = (ViewPager) view.findViewById(R.id.vp_youRen_topPages);
        pages_vp = (ViewPager) view.findViewById(R.id.vp_youRen_pages);
        subtitles = (TabLayout) view.findViewById(R.id.tl_youRen_subtitles);
        points_ll = (LinearLayout) view.findViewById(R.id.ll_youRen_points);
        youLiao_iv = (ImageView) view.findViewById(R.id.iv_youRen_youLiao);
    }


}
